<%@	page import ="java.util.ArrayList" %>
<%@	page import ="java.util.Iterator" %>
<%@	page import ="java.util.List" %>

<%@	page import ="com.adisi.objetos.Cliente" %>
<%@	page import ="com.adisi.objetos.Telefono" %>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html>
<jsp:directive.include file="headerComun.jsp" />
<body>
<div class="container">
	<jsp:directive.include file="menuNavegacion.jsp" />
	<%
		ArrayList<Cliente> clientes = new ArrayList<Cliente>();
		String msg = null;
		String msgType = null;
		boolean hayDisponibles = false; 			
	
		try {
			clientes = (ArrayList<Cliente>)request.getAttribute("clientes");		
			msg = (String)request.getAttribute("msg");
			msgType = (String)request.getAttribute("msg_type");
			hayDisponibles = Boolean.parseBoolean((String)request.getAttribute("hayDisponibles")); 			
		}
		catch(NullPointerException e){
			//out.print(e.getMessage());
		};
		
		if(msgType==null) msgType = "default";
			if(msg!=null) { 
	%>
	<script type="text/javascript">
	$(document).ready(function(){
		$('#alert_placeholder').append('<div class="alert alert-<%=msgType %> fade in "><button type="button" class="close" data-dismiss="alert">&times;</button><%=msg%></div>');
    	alertTimeout(3000);
	});
    </script>
	<% } %>
	
	<div class="row clearfix">	
		<div class="col-md-4 column">
			<h3>Clientes</h3>
		</div>
		<div class="col-md-8 column">
			<form class="navbar-right form-inline" role="login" action="#">
				<div class="form-group">
					<label class="sr-only" for="Search">Buscar</label>
					<input type="text" class="form-control" id="Search" placeholder="Introduce criterio de b&uacute;squeda" style="width: 340px;">
				</div>
				<button type="button" class="btn btn-default" title="Buscar">
					<span class="glyphicon glyphicon-search"></span>
				</button>				
			</form>			
		</div>
	</div>
	<div class="row clearfix">
		<div class="col-md-12 column">
			<div class="table-responsive">
				<table class="table table-striped table-bordered table-hover">
					<thead>
					    <tr>
							<th>Nombre</th>
							<th>Tel&eacute;fono</th>
							<th>Documento</th>
							<th>Acciones
								<% if(Seguridad.validarUsuarioProceso(usuario, "AltaCliente")) { %>
								<div class="btn-group pull-right btn-group-sm">
									<a type="button" class="btn btn-default " title="Agregar cliente" href="cliente?ad">
										<span class="glyphicon glyphicon-plus" style="color:green"></span>
									</a>
								</div>
								<% } %>
							</th>
						</tr>
					</thead>
					<tbody>
						<%
							
							for(int i = 0; i < clientes.size(); i++) {
								int ui = clientes.get(i).getIdCliente();
								ArrayList<Telefono> telefonos = clientes.get(i).getTelefonos();
								Telefono telefono;
								if(telefonos.size()>0)
									telefono = telefonos.get(0);
								else
									telefono = new Telefono();
									
								
						%>
						<tr>
							<td><%=clientes.get(i).getNombreCompleto()%></td>
							<td><%=telefono.getNumero()%></td>
							<%if(clientes.get(i).getDocumento()==null){ %>
							<td></td>
							<%}else{ %>
							<td><%=clientes.get(i).getDocumento().getTipo().toString() %>&nbsp;<%= clientes.get(i).getDocumento().getNumero() %></td>
							<%}; %>
							<td>
								<div class="btn-group btn-group-sm">
									<% if(hayDisponibles && Seguridad.validarUsuarioProceso(usuario, "AltaViaje")) { %>
									<a type="button" class="btn btn-default" title="Despachar" href="">
										<span class="glyphicon glyphicon-road"></span>
									</a>
									<%} %>								
									<% if(Seguridad.validarUsuarioProceso(usuario, "ModificaCliente")) { %>
									<a type="button" class="btn btn-default" title="Modificar datos" href="cliente?ed=<%= ui %>">
										<span class="glyphicon glyphicon-edit"></span>
									</a>									
									<%} %>
									<a type="button" class="btn btn-default" title="Imprimir datos" href="cliente?pr=<%= ui %>">
										<span class="glyphicon glyphicon-print"></span>
									</a>
									<% if(Seguridad.validarUsuarioProceso(usuario, "BajaCliente")) { %>
									<a type="button" class="confirm btn btn-default" title="Eliminar" href="cliente?bo=<%= ui %>">
										<span class="glyphicon glyphicon-trash"></span>
									</a>										
									<%} %>
								</div>							
							</td>
						</tr>
						<% }; %>
						
					</tbody>				
				</table>
			</div>
		</div>
	</div>
</div>

</body>
</html>